﻿using System.Web.Security;

namespace SubSonic.Security.Data{
    public partial class User{
        /// <summary>
        /// MembershipUser representation of user
        /// </summary>
        /// <param name="providerName">ProviderName (needed for creation of MembershipUser)</param>
        /// <returns>MembershipUser rep of User object</returns>
        public MembershipUser MemUserObj(string providerName){
            return new MembershipUser(providerName, this.Username, this.UserID, this.Email, this.SecurityQuestion, string.Empty, this.IsValid, this.IsValid, this.DateCreated, this.LastLogin, this.LastLogin, this.DateCreated, this.DateCreated);
        }

        /// <summary>
        /// Deletes related data to user 
        /// before deleting the user
        /// </summary>
        /// <remarks>Implement this as needed</remarks>
        public void DeleteAllRelatedData(){

        }

        /// <summary>
        /// Updates a user record from MembershipUser object
        /// </summary>
        /// <param name="mu">MembershipUser object</param>
        public void Update(MembershipUser mu){
            this.Email = mu.Email;
            this.DateCreated = mu.CreationDate;
            this.IsValid = mu.IsApproved;
            this.LastLogin = mu.LastActivityDate;
            this.SecurityQuestion = mu.PasswordQuestion;
            this.Save();
            
        }

    }
}

